﻿using XiaoMan.Model.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BLL;
using DAL;
using System.Data.OleDb;
using System.Data;
using System.IO;
using XiaoMan.Service;

namespace XiaoMan.BLL
{

    public class Sys_UsersService : BaseService<Sys_Users>
    {

        public List<Sys_Users> GetList()
        {
            List<Sys_Users> users = this.GetList(u => true);
            return users;
        }
        public Sys_Users GetUserByID(int id)
        {
            Sys_Users user = this.GetList(u => u.UserID == id).FirstOrDefault();
            return user;
        }
        public Sys_Users CheckLogOn(string username, string password)
        {
            Sys_Users user = this.GetList(u => u.UserName == username && u.Password == MD5Manager.Gen_MD5(password)).FirstOrDefault();
            return user;
        }
        public Sys_Users CheckLogOn(string wxopenid)
        {
            Sys_Users user = this.GetList(u => u.WeChat == wxopenid).FirstOrDefault();
            return user;
        }
        public bool EditUser(Sys_Users user)
        {
            return this.Update(user);
        }
        public bool AddWeChatUser(Sys_Users Sys_Users)
        {
            return this.Add(Sys_Users);
        }
    }


    public class Sys_UserInfoService : BaseService<Sys_UserInfo>
    {

        public List<Sys_UserInfo> GetList()
        {
            List<Sys_UserInfo> userInfos = this.GetList(u => true);
            return userInfos;
        }

        public Sys_UserInfo GetUserInfoByID(int id)
        {
            Sys_UserInfo userInfo = this.GetList(u => u.UserInfoID == id).FirstOrDefault();
            return userInfo;
        }

        public bool EditUserInfo(Sys_UserInfo userInfo)
        {
            return this.Update(userInfo);
        }

        public Sys_UserInfo GetUserInfoByUserID(int userid)
        {
            Sys_UserInfo user = this.GetList(u => u.UserID == userid).FirstOrDefault();
            return user;
        }
    }

    public class Sys_DiseaseService : BaseService<Sys_Disease>
    {

        public List<Sys_Disease> GetList()
        {
            List<Sys_Disease> userInfos = this.GetList(d => true);
            return userInfos;
        }

        public Sys_Disease GetDiseaseByID(int id)
        {
            Sys_Disease diseaseInfo = this.GetList(d => d.DiseaseID == id).FirstOrDefault();
            return diseaseInfo;
        }

        public bool EditDisease(Sys_Disease disease)
        {
            return this.Update(disease);
        }
    }

    public class Sys_UserAndDiseaseService : BaseService<Sys_UserAndDisease>
    {
        public Sys_UserAndDisease GetUserAndDisease(int userid, int diseaseID)
        {
            Sys_UserAndDisease userAndDisease = this.GetList(u => u.UserID == userid && u.DiseaseID == diseaseID).FirstOrDefault();
            return userAndDisease;
        }

        public bool AddUserAndDisease(Sys_UserAndDisease userAndDisease)
        {
            return this.Add(userAndDisease);
        }

        public bool DeleteUserAndDisease(Sys_UserAndDisease userAndDisease)
        {
            return this.Delete(userAndDisease);
        }
    }


    public class Sys_AdminUserAndDiseaseService : BaseService<Sys_AdminUserAndDisease>
    {
        public Sys_AdminUserAndDisease GetAdminUserAndDisease(int userid, int diseaseID)
        {
            Sys_AdminUserAndDisease adminUserAndDisease = this.GetList(a => a.UserID == userid && a.DiseaseID == diseaseID).FirstOrDefault();
            return adminUserAndDisease;
        }

        public bool AddAdminUserAndDisease(Sys_AdminUserAndDisease adminUserAndDisease)
        {
            return this.Add(adminUserAndDisease);
        }

        public bool DeleteAdminUserAndDisease(Sys_AdminUserAndDisease adminUserAndDisease)
        {
            return this.Delete(adminUserAndDisease);
        }

        public List<Sys_AdminUserAndDisease> GetListByUserID(int userid)
        {
            List<Sys_AdminUserAndDisease> adminUserAndDiseases = this.GetList(a => a.UserID==userid);
            return adminUserAndDiseases;
        }
    }

    public class Sys_RelationService : BaseService<Sys_Relation>
    {
        public Sys_Relation GetRelation(int userid, int followUserID)
        {
            Sys_Relation relation = this.GetList(r => r.UserID == userid && r.FollowUserID==followUserID).FirstOrDefault();
            return relation;
        }

        public bool AddRelation(Sys_Relation relation)
        {
            return this.Add(relation);
        }

        public bool DeleteRelation(Sys_Relation relation)
        {
            return this.Delete(relation);
        }
    }

    public class Sys_RegionService : BaseService<Sys_Region>
    {
    }

    public class Sys_ConfigService : BaseService<Sys_Config>
    {
    }
    public class Forum_Topic_BackService : BaseService<Forum_Topic_Back>
    {
    }

    public class Forum_TopicService : BaseService<Forum_Topic>
    {
    }

    public class DiaryService : BaseService<Diary>
    {
    }
}
